import { setRootAPI, setRootSchema, getApiMap, getSchemaMap } from './store';
import { LoadData } from './types';
import { startParseApi } from './parse/parseApi';
import {
  parseControllers,
  type controllersResult,
  type controllerResult,
} from './parse/parseControllers';

export {
  type LoadData,
  type controllersResult,
  type controllerResult,
  parseControllers,
};

export function loadData(data: LoadData) {
  // 接口数据
  const apiCollection = data.apiCollection;
  const rootApi = apiCollection[0].items;
  setRootAPI(rootApi);
  // 模型数据
  const schemaCollection = data.schemaCollection;
  const rootSchema = schemaCollection[0].items;
  setRootSchema(rootSchema);
}

export function start() {
  startParseApi();

  const schemaMap = getSchemaMap();
  const apiMap = getApiMap();

  return {
    schemaMap,
    apiMap,
  };
}
